const book = E = {
	page(_pageNo, _pageSize, name, phone, no, wname, state) {
		let _tbody = $('#_tbody');
		$.ajax({
			url: url.path + 'dingdan/list',
			type: 'get',
			data: {
				pageNo: _pageNo,
				pageSize: _pageSize,
				name: name,
				phone: phone,
				no: no,
				wname: wname,
				state: state
			},
			dataType: 'json',
			success: function(res) {
				console.log(res);
				if (res.code == 200) {
					_tbody.empty(); // 将容器清空
					let list = res.data.dataList;

					$('#p_no').html('').html(res.data.pageNo);
					$('#p_count').html('').html(res.data.totalPageCount);
					$('#zong').html('').html(res.data.totalCount);

					$(list).each(function(i, e) {
						if (e.state == 1) {
							state = '待派单';
							let _tds = $(`
							<div class="workorder-card position-relative">
										<div class="workorder-status"> ` + state + ` </div>
											<div class="d-flex justify-content-between align-items-start">
												<div>
													<span> 工单编号：</span>
													<span class="text-secondary">` + e.dno + `</span>
													<i class="bi bi-share ms-2"></i>
												</div>
											</div>
													<p class="my-1">维修日期：<span class="text-primary">` + E.timestampToDate(e.date) + `</span></p>
													<p class="my-1">故障位置：<span class="text-dark">` + e.address + `</span></p>
													<p class="my-1">联系人：<span class="text-dark">` + e.lxrname + `</span></p>
													<p class="my-1">联系电话：<span class="text-dark">` + e.lxrphone + `</span></p>
													<p class="my-1">故障描述：<span class="text-dark">` + e.description + `</span></p>
													<div class="mt-2 d-flex gap-2">
												<button class="btn btn-outline-secondary btn-sm"> 取消工单 </button>
												<button class="btn btn-outline-primary btn-sm"> 指派 </button>
										</div>
							</div>
							    `)
							_tds.click(function() {
								location.href = "yyxxDPD.html?did=" + e.id;
							})
							_tbody.append(_tds);
						}


					});
				}
			}
		});
	},
	timestampToDate(timestamp) {
		const date = new Date(timestamp); // 将时间戳转换为Date对象
		const options = {
			year: 'numeric',
			month: 'long',
			day: 'numeric'
		}; // 定义日期格式
		return new Intl.DateTimeFormat('zh-CN', options).format(date); // 使用Intl.DateTimeFormat进行格式化
	},
	first() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		E.page(_pageNo, _size, _lxrname, _lxrphone, _no, _wname, _state);
	},
	tiao() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		E.page(1, _size, _lxrname, _lxrphone, _no, _wname, _state);
	},
	last() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		let _p_count = $('#p_count').html();
		E.page(_pageNo, _size, _lxrname, _lxrphone, _no, _wname, _state);
	},
	prev() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		let _pageNo = $('#p_no').html();
		if (_pageNo > 1) {
			_pageNo--;
			E.page(_pageNo, _size, _lxrname, _lxrphone, _no, _wname, _state);
		} else {
			alert('已经是第一页了')
		}

	},
	next() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		let _pageNo = $('#p_no').html();
		let _p_count = $('#p_count').html();
		if (_pageNo < _p_count * 1) {
			_pageNo++;
			E.page(_pageNo, _size, _lxrname, _lxrphone, _no, _wname, _state);
		} else {
			alert('已经是最后一页了')
		}
	}
}
$(function() {
	E.page(1, 10, '', '', '', '', '');

	$('#chooseSize').change(function() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _size = $(this).val();
		E.page(1, _size, _lxrname, _lxrphone, _no, _wname, _state);
	})

	$('#first').click(function() {
		E.first();
	})

	$('#last').click(function() {
		E.last();
	})

	$('#toPno').blur(function() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _pageNo = $('#toPno').val();
		let _pageSize = $('#chooseSize').val();
		let _p_count = $('#p_count').html();
		if (_pageNo <= _p_count * 1) {
			E.page(1, _size, _lxrname, _lxrphone, _no, _wname, _state);
		} else {
			alert('不能大于总页数')
		}

	})

	$('#x').click(function() {
		let _lxrname = $('#lxrname').val();
		let _lxrphone = $('#lxrphone').val();
		let _wname = $('#wname').val();
		let _no = $('#no').val();
		let _state = $('#state').val();
		let _size = $('#chooseSize').val();
		E.page(1, _size, _lxrname, _lxrphone, _no, _wname, _state);
	})

	$('#btn_search').click(function() {
		let _data = $('#name').val();
		let _size = $('#chooseSize').val();
		E.page(1, _size, _data);
	})

	$('#prev').click(function() {
		E.prev();
	})

	$('#next').click(function() {
		E.next();
	})


})